import { find } from "cc";
import { Component, Label, Node, Sprite, tween, Vec3, _decorator, UIOpacity, UITransform, size } from "cc";
import { App } from "../App";
import UtilTool from "./UtilTool";

const {ccclass, property} = _decorator;

/**
 * 提示框
 * 默认第一个按钮为确定按钮，第二个按钮为取消按钮
 */
@ccclass('TipBox')
export class TipBox extends Component {
    @property(Node)
    desTxt: Node = null;

    @property({ type: Node })
    Btn_close: Node

    @property({ type: Node })
    btn_1: Node

    @property({ type: Node })
    btn_2: Node

    private func = null

    onLoad () {
        
    }

    start () {
        UtilTool.setScreen(this.node)
        UtilTool.nodeActive(find("bg",this.node),5,0.16)
    }

    /**
     * 
     * @param data.content 显示内容
     * @param data.btnType 按钮显示类型 [1]只显示确认按钮 [2]只显示关闭按钮 [3]确认、关闭都显示 [4]确认、取消按钮
     * @param data.func 确认按钮回调 返回点击的按钮索引 0确认 1取消
     * @param data.btnTexts 按钮文字列表 为空时，默认 [0]确认 [1]取消
     */
    public setDesData(data)
    {
        this.func = data.func
        this.Btn_close.active = (data.btnType==2 || data.btnType==3)
        this.btn_1.active = (data.btnType==1 || data.btnType==3 || data.btnType==4)
        this.btn_2.active = (data.btnType==4)
        this.desTxt.getComponent(Label).string = data.content

        let btnTexts = data.btnTexts || [App.language.getLanguageLab(38),App.language.getLanguageLab(2027)]
        this.btn_1.getComponentInChildren(Label).string = btnTexts[0]
        this.btn_2.getComponentInChildren(Label).string = btnTexts[1]
    }

    public clickClose() {
        App.Audio.playOneShot("click")
        this.node.destroy()
    }

    /**
     * 点击按钮返回
     * @param event 
     * @param btnIndex 
     * 回调事件 返回点击的按钮索引 0确认 1取消
     */
    public clickBtn(event, btnIndex) {
        App.Audio.playOneShot("click")
        if (this.func) this.func(btnIndex)
        this.node.destroy()
    }
    
}
